#include <iostream>

using namespace std;
const int N=1e6+10;

int a[N],idx[N],b[N];
int f[N],len;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		idx[a[i]]=i;
	}
	
	for(int i=1;i<=n;i++)
	{
		int num;
		scanf("%d",&num);
		b[i]=idx[num];
	}
	f[0]=-1;
	for(int i=1;i<=n;i++)
	{
		if(b[i]==0)
			continue;
		if(b[i]>f[len])	
		{
			f[++len]=b[i];
		}
		else{
			int left=1,right=len;
			while(left<right)
			{
				int mid=left+(right-left)/2;
				if(b[i]>f[mid])
				{
					left=mid+1;
				}
				else{
					right=mid;
				}
			}
			f[left]=b[i];
		}
	}
	cout<<len<<endl;
	return 0;
}
